package com.wei.shopping.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.wei.shopping.dao.NoticesMapper;
import com.wei.shopping.entrty.PageResult;
import com.wei.shopping.entrty.QueryPageBean;
import com.wei.shopping.pojo.Notices;
import com.wei.shopping.service.NoticesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

@Service
@Transactional
public class NoticesServiceImpl implements NoticesService {
    @Resource
    private NoticesMapper noticesMapper;
    /**
     * 添加通知
     *
     */
    @Override
    public void addnotices(Notices notices){
        noticesMapper.addnotices(notices);
    }

    /**
     * 查找所有通知
     * @param queryPageBean
     * @param userid
     * @return
     */
    @Override
    public PageResult findAllByUserId(QueryPageBean queryPageBean, String userid,String tpname) {
        PageHelper.startPage(queryPageBean.getCurrentPage(),queryPageBean.getPageSize());
        Page<Notices> pages = noticesMapper.findAllByUserId(queryPageBean.getQueryString(),userid,tpname);
        return new PageResult(pages.getTotal(),pages.getResult());
    }

    /**
     * 设置消息为已读
     * @param noticesid
     */
    @Override
    public void isread(String noticesid){
        noticesMapper.isread(noticesid);
    }

    /**
     * 获取最新消息
     * @param userid
     * @return
     */
    @Override
    public List<Notices> lastnotices(String userid){
        List<Notices> lastnotices = noticesMapper.lastnotices(userid);
        return lastnotices;
    }
}
